﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hardanger.Features.ServerFuzzer.DetectionEngine;
using Hardanger.Features.ServerFuzzer.ServerFuzzerEngine;
using System.Collections.ObjectModel;
using Hardanger.View;
using Hardanger.View.FuzzerConfig;
using System.Windows;

namespace Hardanger.Features.ServerFuzzer
{
    public class ServerFuzzingItem
    {
        private RelayCommand _configureCommand;
        public RelayCommand ConfigureCommand
        {
            get
            {
                if (_configureCommand == null)
                    _configureCommand = new RelayCommand(r => ShowConfigurationWindow());
                return _configureCommand;
            }
        }

        public bool Enabled { get; set; }
        public string ServerFuzzingEngineName { get; set; }

        private IServerFuzzerEngine _serverFuzzingEngine;
        public IServerFuzzerEngine ServerFuzzingEngine 
        {
            get
            {
                if (_serverFuzzingEngine == null)
                    _serverFuzzingEngine = ServerFuzzerEngineFactory.Create(ServerFuzzingEngineName);
                return _serverFuzzingEngine;
            }
        }
        public FuzzerSettingType DataType { get; set; }
        public IDetectionEngine DetectionEngine { get; set; }
        public ObservableCollection<string> AllFuzzers
        {
            get
            {
                return ServerFuzzerEngineFactory.GetAllFuzzers();
            }
        }

        private void ShowConfigurationWindow()
        {
            Window config = null;

            
            switch(ServerFuzzingEngineName.ToLower())
            {
                case "basicrandomfuzzer":
                    config = new BasicRandomFuzzerConfig();
                    break;
                case "repeatingstringfuzzerengine":
                    config = new RepeatingStringFuzzerConfig();
                    break;
            }

            if (config == null)
                return;

            config.DataContext = ServerFuzzingEngine;
            config.Show();
        }
    }
}
